package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.LevelService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/level")
public class LevelManageController {

    @Resource
    LevelService levelService;

    //添加等级
    @PostMapping("")
    @SaAdminCheckPermission("admin:level:add")
    public Result<String> addLevel(@RequestBody LevelCommand command) {
        levelService.addLevel(command);
        return Result.ok("添加等级成功");
    }

    //更新等级
    @PutMapping("")
    @SaAdminCheckPermission("admin:level:update")
    public Result<String> updateLevel(@RequestBody LevelCommand command) {
        levelService.updateLevel(command);
        return Result.ok("更新等级成功");
    }

    //获取等级列表
    @GetMapping("list")
    public Result<PageDTO<LevelDTO>> getLevelList(PageRequest request){
        PageDTO<LevelDTO> levelList = levelService.getLevelList(request);
        return Result.ok(levelList);
    }

    //删除等级
    @DeleteMapping("{id}")
    @SaAdminCheckPermission("admin:level:delete")
    public Result<String> deleteLevel(@PathVariable Long id) {
        DeleteLevelOperateDTO deleteLevelOperateDTO = levelService.deleteLevel(id);
        return Result.ok("删除等级成功");
    }

    //批量删除等级
    @DeleteMapping("batch")
    @SaAdminCheckPermission("admin:level:batchdelete")
    public Result<String> deleteLevels(@RequestBody BatchDeleteCommand command) {
        List<DeleteLevelOperateDTO> deleteLevelOperateDTOS = levelService.deleteLevels(command);
        return Result.ok("批量删除等级成功");
    }

}
